/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AirLine;

import Database.Seats;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.sql.*;

/**
 *
 * @author Administrator
 */
public class Flight implements Comparable, Serializable {

    private Airport departureAirport;
    private Airport destinationAirport;
    private int price;
    private String code;
    private Timestamp departureTime;
    private Timestamp arrivalTime;
    //private ArrayList freeSeats;
    private Airline airline;
    private String database;
    private Set<Seat> freeSeats;
    private String plane;

    public Flight(String code, Airport from, Airport to, int price, Timestamp depTimestamp, Timestamp arrTimestamp, Set freeSeats, String database, Airline airline, String planeId) {
        this.plane=planeId;
        this.code = code;
        departureAirport = from;
        destinationAirport = to;
        this.price = price;
        this.departureTime = depTimestamp;
        this.arrivalTime = arrTimestamp;
        this.freeSeats = freeSeats;
        this.airline = airline;
        this.database=database;
    }
    
        
    
    public String getPlaneId()
    {
        return plane;
    }
    
    public Set<Seat> getFreeSeats()
    {
        return freeSeats;
    }
    
    public int getNumberOfFreeSeats() {
        return freeSeats.size();
    }

    public String getCode() {
        return code;
    }

    public int getPrice() {
        return price;
    }

    public long getDuration() {
        return arrivalTime.getTime() - departureTime.getTime();
    }

    public Timestamp getDepartureTime() {
        return departureTime;
    }

    public Timestamp getArrivalTime() {
        return arrivalTime;
    }

    public Airport getDepartureAirport() {
        return departureAirport;
    }

    public Airport getDestinationAirport() {
        return destinationAirport;
    }

    public String getDatabase() {
        return database;
    }
    
    public Airline getAirline()
    {
        return airline;
    }
    
    /*
     * Dont know if this compareTo function is accurate?
     */
    
    public int compareTo(Object o) {
        if (o instanceof Flight) {
            return compareTo((Flight) o);
        } else {
            System.out.println("NJAAAA, INTE HIT!!!");
            
            return -1;
        }
    }

    public int compareTo(Flight f) {
            if (getCode().compareTo(f.getCode()) == 0) {
               return f.getDepartureTime().compareTo(getDepartureTime());
            }
                return getCode().compareTo(f.getCode());
    }
}
